import { getDeviceTypeList } from '../../api/sensor'

const state = {
  tableData: [],
  count: '',
  index: '',
  showAddBox: false,
  showWriteBox: false

}

const mutations = {
  // 设置更新列表
  update_list (state, tableData) {
    state.tableData = tableData
  },
  // 总数
  list_count (state, count) {
    state.count = count
  },
  show_addBox (state, boolean) {
    state.showAddBox = boolean
  },
  show_writeBox (state, boolean) {
    state.showWriteBox = boolean
  }
}

const actions = {
  // 刷新列表
  updateTable (context, index) {
    return new Promise((resolve, reject) => {
      getDeviceTypeList(index, 10).then(res => {
        if (res.data.code === (200 || '200')) {
          // console.log(res)
          context.commit('update_list', res.data.data.data)
          context.commit('list_count', res.data.data.count)
        }
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  }
}
export default {
  namespaced: true,
  actions,
  state,
  mutations
}
